﻿using Autofac;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Reflection;
using Newtonsoft.Json;
using WCS.Entities.Api;
using WCS.Entities.TES;
using WCS.ViewModels;

namespace JuionWareHouse.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TestController : ControllerBase
    {

        private readonly ILifetimeScope lifetimeScope;
        public TestController(ILifetimeScope lifetimeScope)
        {
            this.lifetimeScope = lifetimeScope;
        }

        /// <summary>
        /// 测试添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult TestCreate([FromBody] TestCreateDto testCreate)
        {
            try
            {
                using var db = lifetimeScope.BeginLifetimeScope().Resolve<ISqlSugarClient>().CopyNew();
                var anemodel = new Ianeway
                {
                    warehouseID = testCreate.warehouseID,
                    requestID = testCreate.requestID,
                    clientCode = testCreate.clientCode,
                    desType = testCreate.desType,
                    srcType = 1,
                    podID = testCreate.podID,
                    priority = testCreate.priority,
                    bizID = testCreate.bizID,
                    replacePodTask = testCreate.replacePodTask,
                    desExt = JsonConvert.SerializeObject(testCreate.desExt),
                    desStorageID = testCreate.desStorageID,
                };
                var isOk = db.Insertable(anemodel).ExecuteCommand();
                return isOk > 0 ? ApiResultHelp.Success() : ApiResultHelp.Error($"添加失败");
            }
            catch (Exception ex)
            {
                return ApiResultHelp.Error($"异常抛出，异常信息：{ex.Message}");
            }
        }
    }
}
